<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="common/include :: header('编辑窗口')"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-window-add" th:object="${window}">
        <input name="id" type="hidden" th:field="*{id}"/>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">窗口名称：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="windowName" required th:value="*{windowName}">
            </div>
        </div>

		<div class="form-group">
			<label class="col-sm-3 control-label is-required">封面图片：</label>
			<div class="col-sm-8">
				<input type="hidden" class="form-control" id="imageSrc" name="coverSrc" th:value="*{coverSrc}">
				<img th:src="*{coverSrc}" width="50%" id="imgUrl">
				<br>
				<button type="button" class="imgBtn">浏览</button>
			</div>
		</div>

        <div class="form-group">
            <label class="col-sm-3 control-label is-required">窗口位置：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="address" required th:value="*{address}">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">联系电话：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="mobile" required th:value="*{mobile}">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">窗口类型：</label>
            <div class="col-sm-8">
                <select name="type" class="form-control m-b" th:with="items=${@dict.getType('business_window_type')}">
                    <option th:each="item : ${items}" th:text="${item.label}"
                            th:value="${item.value}" th:field="*{type}"></option>
                </select>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label is-required">打包费用：</label>
            <div class="col-sm-8">
                <input class="form-control" type="number" name="packageCharge" required th:value="*{packageCharge}">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">配送费用：</label>
            <div class="col-sm-8">
                <input class="form-control" type="number" name="deliveryCharge" required th:value="*{deliveryCharge}">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">最低消费：</label>
            <div class="col-sm-8">
                <input class="form-control" type="number" name="minCharge" required th:value="*{minCharge}">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">所属餐厅：</label>
            <div class="col-sm-8">
                <select name="canteenId" class="form-control m-b" th:value="*{canteenId}">
                    <option th:each="item : ${canteens}" th:text="${item.canteenName}"
                            th:value="${item.id}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">窗口介绍：</label>
            <div class="col-sm-8">
				<textarea class="form-control" name="introduction" th:utext="*{introduction}"></textarea>
            </div>
        </div>
    </form>
</div>
<th:block th:include="common/include :: footer"/>
<!-- 文件上传插件 -->
<link type="text/css" rel="stylesheet" href="/plugins/uploadifive/uploadifive.css"/>
<script type="text/javascript" src="/plugins/uploadifive/jquery.uploadifive.min.js"></script>
<!-- 富文本插件 -->
<script src="/plugins/ckeditor/ckeditor.js"></script>
<th:block th:include="common/include :: datetimepicker"/>
<script type="text/javascript">
    var prefix = ctx + "/business/windows";
	//表单提交验证
	$(function () {
		//图片上传
		$('.imgBtn').uploadifive({
			'auto': true,  //自动发起图片上传请求
			'uploadScript': '/business/upload',   //处理上传文件的请求路径
			'buttonClass': "btn-link",
			'fileObjName': 'file',   //上传文件参数名
			'buttonText': '浏览...',
			'fileType': 'image',
			'multi': false,
			'fileSizeLimit': 5242880,
			'removeCompleted': true, //取消上传完成提示
			'uploadLimit': 1,
			//'queueSizeLimit'  : 10,
			'overrideEvents': ['onDialogClose', 'onError'],    //onDialogClose 取消自带的错误提示
			'onUploadComplete': function (file, data) {
				let result = JSON.parse(data);
				if (0 === result.code) {
					$("#imgUrl").attr("src", result.url);
					$("#imageSrc").val(result.url);
					$.modal.msg("上传成功！");
				} else {
					$.modal.alertError(result.msg);
				}
			},
			onFallback: function () {
				$.modal.alertError("该浏览器无法使用!");
			}
		});
	});
    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/edit", $('#form-window-add').serialize());
        }
    }
</script>
</body>
</html>
